﻿Imports System.Data.OleDb

Public Class AddArtist
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_AddArtist_Click(sender As Object, e As EventArgs) Handles btn_AddArtist.Click



        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("3dBuzzDatabase").ConnectionString)

        'Dim SqlStringExists As String = "SELECT * FROM Artists WHERE ASPUserName = @f20"
        Dim SqlStringExists As String = "SELECT aspnet_Users.[UserId], Artists.[ASPUserName]  FROM aspnet_Users INNER JOIN Artists ON aspnet_Users.[UserId] = Artists.[ASPUserName] WHERE aspnet_Users.[UserName] = @f20"
        Dim cmdExists As OleDbCommand = New OleDbCommand(SqlStringExists, oleDbConn)
        cmdExists.CommandType = CommandType.Text
        cmdExists.Parameters.AddWithValue("@f20", User.Identity.Name)
        oleDbConn.Open()
        Dim dr As OleDbDataReader = cmdExists.ExecuteReader()
        If dr.HasRows() Then
            'go to edit page
            Response.Redirect("~/EditArtist.aspx")
        Else
            Dim findASPIdSqlString As String = "SELECT aspnet_Users.[UserId] FROM aspnet_Users WHERE aspnet_Users.[UserName] = @f30"
            Dim findASPIdcmd As OleDbCommand = New OleDbCommand(findASPIdSqlString, oleDbConn)
            findASPIdcmd.CommandType = CommandType.Text
            findASPIdcmd.Parameters.AddWithValue("@f30", User.Identity.Name)
            Dim drId As OleDbDataReader = findASPIdcmd.ExecuteReader()
            Dim storeid As Integer
            drId.Read()
            storeid = drId.Item("UserId")
            Dim storeida As String = storeid.ToString





            Dim SqlString As String = "Insert into Artists(ASPUserName,Title,Firstname,Surname,Nickname,Addr1,Addr2,Town,County, Postcode, Country, TelMobile, Fax, Email, WebURL, Companyname, Telcomp) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11,@f12,@f13,@f14,@f15,@f16,@f17)"
            Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", storeida)
            cmd.Parameters.AddWithValue("@f2", tb_Title.Text)
            cmd.Parameters.AddWithValue("@f3", tb_Firstname.Text)
            cmd.Parameters.AddWithValue("@f4", tb_Surname.Text)
            cmd.Parameters.AddWithValue("@f5", tb_Nickname.Text)
            cmd.Parameters.AddWithValue("@f6", tb_Addr1.Text)
            cmd.Parameters.AddWithValue("@f7", tb_Addr2.Text)
            cmd.Parameters.AddWithValue("@f8", tb_Town.Text)
            cmd.Parameters.AddWithValue("@f9", tb_County.Text)
            cmd.Parameters.AddWithValue("@f10", tb_Postcode.Text)
            cmd.Parameters.AddWithValue("@f11", tb_Country.Text)
            cmd.Parameters.AddWithValue("@f12", tb_Mobile.Text)

            cmd.Parameters.AddWithValue("@f13", tb_Fax.Text)

            cmd.Parameters.AddWithValue("@f14", tb_Email.Text)
            cmd.Parameters.AddWithValue("@f15", tb_URL.Text)
            cmd.Parameters.AddWithValue("@f16", tb_Company.Text)
            cmd.Parameters.AddWithValue("@f17", tb_CompanyNumber.Text)
            'oleDbConn.Open()
            cmd.ExecuteNonQuery()
            oleDbConn.Close()
            oleDbConn.Dispose()
            Response.Redirect("~/Artists.aspx")
        End If


    End Sub
End Class